var inquiry_id = GetQueryString('inquiry_id');
var state = GetQueryString("inquiry_status");
var customer_codes=""
var matcher_id = GetQueryString('matcher_id');
var member_id=GetQueryString('member_id');
var matching_name = JSON.parse(web.readCookie("loginData")).user.name;
var fix_price_id = GetQueryString('fix_price_id');
var fix_price_name = JSON.parse(web.readCookie("loginData")).user.name;
var customer_id = GetQueryString('customer_id');
var receiver_province = GetQueryString('receiver_province');
var warehouse_code=""
var addintercepts=0
var verificationall=true
var platform = GetQueryString('platform');
function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
};
//获取操作人的姓名及ID
var loginData = JSON.parse(web.readCookie("loginData"));
var service_name = loginData.user.name;
var service_id = loginData.user.user_ID;
// 商品基础信息
var baseParams = {
    "async": false,
    "crossDomain": true,
    "url": root.xunjiadan.getProductInfo,
    "method": "POST",
    "headers": {
        "Content-Type": "application/x-www-form-urlencoded"
    },
    "data": {
        "inquiry_id": inquiry_id                             //询价单编号
    }
}

$.ajax(baseParams).done(function (result) {
    warehouse_code=result.warehouse_code;
    customer_codes=result.customer_code
    $('#inquiry_id').text(result.inquiry_id);
    $('#inquiry_name').text(result.inquiry_name);
    $('#created_time').text(result.created_time);
    $('#collect_address').text(result.receiver_province_name + '/' + result.receiver_city_name + '/' + result.receiver_area_name + '/' + result.detail_address);
    $('#linkman').text(result.linkman);
    $('#linkman_phone').text(result.linkman_phone);
    $('#customer_name').text(result.customer_name);
    $('#other_explain').text(result.other_explain);
    if(result.source==20){
        $('#platform').text("APP");
    }else {
        $('#platform').text("PC");
    }
    if(result.claim_arrival_time=="1000-01-01"){
        $('#timemin').val("");
    }else {
        $('#timemin').val(result.claim_arrival_time);
    }
    if(result.claim_purchase_time=="1000-01-01 00:00:00"){
        $('#timemax').val("");
    }else {
        $('#timemax').val(result.claim_purchase_time);
    }
});
//备注
var remarkParams = {
    "async": true,
    "crossDomain": true,
    "url": root.xunjiadan.getRemarksList,
    "method": "POST",
    "headers": {
        "Content-Type": "application/x-www-form-urlencoded"
    },
    "data": {
        "inquiry_id": inquiry_id                          //询价单编号
    }
}
$.ajax(remarkParams).done(function (result) {
    if (result.length > 0) {
        $('#remarkTable').show();
    } else {
        $('#remarkTable').hide();
    }
    var html = '';
    for (var i = 0; i < result.length; i++) {
        html += '<tr>'
            + '<td>' + result[i].service_name + '</td>'
            + '<td>' + result[i].result + '</td>'
            + '<td>' + result[i].create_time + '</td>'
            + '<td id="' + result[i].id + '"><a href="javascript:void(0)" class="deleteRemarks">删除</a></td>'
            + '</tr>'
    }
    ;
    $('#remarksList').empty().append(html);
});
// 报价单说明----------------------------------------------开始
var remarkParams = {
    "async": true,
    "crossDomain": true,
    "url": root.xunjiadan.inquiryQuotationExplain,
    "method": "POST",
    "headers": {
        "Content-Type": "application/x-www-form-urlencoded"
    },
    "data": {
        "inquiryId": inquiry_id                          //询价单编号
    }
}
$.ajax(remarkParams).done(function (result) {
    if (result && result.length > 0) {
        $('#offer_table').show();
    } else {
        $('#offer_table').hide();
    }
    var html = '';
    for (var i = 0; i < result.length; i++) {
        html += '<tr>'
            + '<td>' + result[i].serviceName + '</td>'
            + '<td>' + result[i].quotationExplain + '</td>'
            + '<td>' + result[i].createTime + '</td>'
            + '<td id="' + result[i].id + '"><a href="javascript:void(0)" class="deleteRemarks">删除</a></td>'
            + '</tr>'
    }
    ;
    $('#offer_list').empty().append(html);
});
//报价单说明 增加
$('#addoffer_value').click(function () {
    var result = $('#offer_value').val();
    if (result == "") {
        layer.msg('备注不能为空', {icon: 5, time: 1000});
        return false
    }
    var create_time = $.nowDate();
    var addRemParams = {
        "async": true,
        "crossDomain": true,
        "url": root.xunjiadan.addInquiryQuotationExplain,
        "method": "POST",
        "headers": {
            "Content-Type": "application/json"
        },
        "processData": false,
        "data": JSON.stringify({
            "belongInquiryId": inquiry_id,            //询价单编号
            "serviceId": service_id,
            "serviceName": service_name,
            // "create_time": create_time,
            "quotationExplain": result,
            "resultState":10
        })
    }
    //添加备注成功
    $.ajax(addRemParams).done(function (response) {
        $('#remarks').val('');
        if (response.code == '0') {
            $('#offer_table').show();
            $('#offer_list').append('<tr><td>' + response.serviceName + '</td><td>' + response.quotationExplain + '</td><td>' + response.createTime + '</td><td id="' + response.id + '"><a href="javascript:void(0);" class="deleteRemarks">删除</a></td></tr>');
            layer.msg('添加成功！', {icon: 6, time: 1000});
        } else {
            layer.msg(response.response, {icon: 5, time: 1000});
        }
    });
})
//删除 报价单说明
$('#offer_table').on('click', '.deleteRemarks', function () {
    var Result_id = $(this).parent('td').attr('id');
    var ele = $(this);
    var settings6 = {
        "async": true,
        "crossDomain": true,
        "url": root.xunjiadan.deleteInquiryQuotationExplain,
        "method": "POST",
        "headers": {
            "Content-Type": "application/x-www-form-urlencoded"
        },
        "data": {
            "quotationExplainId": Result_id
        }
    }
    $.ajax(settings6).done(function (response) {
        if (response.code == '0') {
            layer.msg('删除成功', {icon: 6, time: 1000});
            ele.parents('tr').remove();
            if ($('#offer_list tr').length == 0) {
                $('#offer_table').hide();
            }
        } else {
            alert(response.message);
        }
    });
});
// 报价单说明----------------------------------------------结束
//商品附件
var fileParams = {
    "async": true,
    "crossDomain": true,
    "url": root.xunjiadan.getFileList,
    "method": "POST",
    "headers": {
        "Content-Type": "application/x-www-form-urlencoded"
    },
    "data": {
        "inquiry_id": inquiry_id                          //询价单编号
    }
}

$.ajax(fileParams).done(function (result) {
    var html = '';
    for (var i = 0; i < result.length; i++) {
        if (result[i].file_name == '') {
            var urlName = result[i].file_path;
            var imgUrl = urlName.substring(0, urlName.indexOf('?'));
            result[i].file_name = imgUrl.substring(imgUrl.lastIndexOf('/') + 1);
        }
        if (result[i].file_type == 'pcx' || result[i].file_type == 'emf ' || result[i].file_type == 'gif' || result[i].file_type == 'bmp ' || result[i].file_type == 'jpg' || result[i].file_type == 'tif' || result[i].file_type == 'jpeg ' || result[i].file_type == 'png' || result[i].file_type == 'rle') {
            text = "查看";
        } else {
            text = "下载";
        }
        var strarea = result[i].file_name ;
        var po = strarea.split(".");
        html += '<li>'
            + '<b>附件' + (i + 1) + ':</b>'
            + '<div style="margin-top: -20px;margin-left: 38px;height: 20px;position: relative;"><a href="' + root.xunjiadan.downLoadFromUrl + '?urlStr=' + encodeURIComponent(result[i].file_path) + '&fileName=' + encodeURIComponent(po[0]) + '">' + text + '</a></div>'
            + '<div class="bg-grey" style="margin-left: 65px;position: relative;top: -25px;">'
            + '<span>' + result[i].file_name + '</span>'
            + '</div></li>';
    }
    $('#fujian').empty().append(html);
    });
var productParams = {
    "async": true,
    "crossDomain": true,
    "url": root.xunjiadan.getProductList,
    "method": "POST",
    "headers": {
        "Content-Type": "application/x-www-form-urlencoded"
    },
    "data": {
        "inquiry_id": inquiry_id                          //询价单编号
    }
};
    //商品清单
        $.ajax(productParams).done(function (data) {
            console.log(data)
            if(data){
                var html='';
                var htmler='';
                for(var i=0;i<data.length;i++){
                    //要求采购时间
                    var datashu,
                        arrivaltime;
                    if(data[i].claim_purchase_time== '1000-01-01'){
                         datashu=""
                    }else {
                         datashu=data[i].claim_purchase_time
                    }
                    if(data[i].claim_arrival_time== '1000-01-01'){
                        arrivaltime=""
                    }else {
                        arrivaltime=data[i].claim_arrival_time
                    }
                    // 商品描述
                    var pic = isProductError(data[i].product_depict,1);
                    var desc = isProductError(data[i].product_depict);
                    //判断商品是否能够修改
                        var price = ''  ///成本价
                        var discount_price ='';//售价
                    //商品序号
                        var order = i+1;
                        var current='';
                        var abnormal_type='';
                        if(data[i].abnormal_type == 20){
                            abnormal_type="异常询价"
                            current='current'
                        }else {
                            abnormal_type=""
                            current=''
                          
                        }
                        if(data[i].spu_id==0||data[i].spu_id==''){ // 未匹配
                            if( data[i].abnormal_type == 20){
                                var  sku_name =data[i].sku_name
                            }else{
                                var  sku_name = '<input value="'+data[i].sku_name+'"/>'
                            }
                           
                            if(data[i].price=='0'){
                                if(data[i].abnormal_type == 20){
                                    var  price = ''; //成本价
                                }else{
                                    var  price = '<input disabled value = ""/>'; //成本价
                                }
                            }else{
                                if(data[i].abnormal_type == 20){
                                    var  price =data[i].price //成本价
                                }else{
                                    var  price = '<input disabled value = "'+data[i].price+'"/>'; //成本价
                                }
                            }
                            if(data[i].discount_price =='0'){
                                if(data[i].abnormal_type == 20){
                                    var  discount_price = ''; //价格
                                }else{
                                    var  discount_price = '<input disabled oninput="checkPrice(this)" value = ""/>'; //价格
                                }
                            }else{
                                if(data[i].abnormal_type == 20){
                                    var  discount_price = data[i].discount_price //价格
                                }else{
                                    var  discount_price = '<input disabled oninput="checkPrice(this)" value = "'+data[i].discount_price+'"/>'; //价格
                                }
                               
                            }
                            if(data[i].abnormal_type == 20){
                                var  order_fillrates = data[i].order_fillrates
                                var  unit_name =data[i].unit_name
                                var addnum=data[i].product_count
                            }else{
                                var  order_fillrates =  '<input maxlength="120" value = "'+data[i].order_fillrates+'"/>';//订货要求
                                var  unit_name = '<input oninput="checkMaxIut(this)" value="'+data[i].unit_name+'"/>'// 单位
                               var addnum='<div class="numberbar"><span onclick="number_decrease(this)" class="number_decrease">-</span><span onclick="number_increase(this)" class="number_increase">+</span><input id="Smallplan" maxlength="5" type="text"  oninput="checkCount(this,'+data[i].product_count+')" class="num_text Numberwo" value="'+data[i].product_count+'"></div>'
                            }
        
                            if(data[i].product_cycle==''||data[i].product_cycle=='0'){   //交货期
                                if(data[i].abnormal_type == 20){
                                    var product_cycle = '1'

                                }else {
                                    var product_cycle = ''

                                }
                            }else{
                                var product_cycle = data[i].product_cycle;
                            }
                        }else { //已匹配
                            var sku_name = data[i].sku_name;
                            var price = '';
                            var discount_price = data[i].discount_price;
                            var order_fillrates = data[i].order_fillrates;
                            var addnum=data[i].product_count
                            var unit_name = data[i].unit_name;
                            if(data[i].product_cycle==''||data[i].product_cycle=='0'){   //交货期
                                var product_cycle = '1'  
                            }else{
                                var product_cycle = data[i].product_cycle;
                            }
                        }
                        if(data[i].discount_price =='0'){
                            var subtotal ='';
                        }else{
                            var subtotal = (parseFloat(data[i].discount_price)*parseInt(data[i].product_count)).toFixed(2);
                        }
                        var explanation=""
                        if(data[i].explanation==null){
                            explanation=""
                        }else {
                            explanation=data[i].explanation
                        }
                        var abnormal_text=data[i].abnormal_text?data[i].abnormal_text:''
                        html+='<tr class="idcans +'+current+'" id="'+data[i].id+'"  iddata="'+data[i].id+'">'
                            +'<td class="rfqg_td1 order">'+order+'</td>'//序号
                            +'<td class="xfqg_td2 commodityCode" sku_id="'+data[i].sku_id+'" spu_id="'+data[i].spu_id+'">'+data[i].sku_code+'</td>'//商品编码
                            +'<td class="xfqg_td3 commodityName">'+data[i].product_name+'</td>'//商品名称
                            +'<td class="rfqg_td4 platformName">'+sku_name+'</td>' //平台商品名称
                            +'<td class="xfqg_td5 fication">'+data[i].product_classify+'</td>'//分类
                            +'<td class="xfqg_td6 brand">'+data[i].brand+'</td>'//品牌
                            +'<td class="xfqg_td7 describe">'+'<img style="width:24px;height:auto;" src="'+pic+'"/>'+desc+'</td>'//商品描述
                            +'<td class="rfqg_td8 Please"> '+order_fillrates+'</td>'//订货要求
                            +'<td class="rfqg_td10 Costprice">'+price+'</td>'//成本价
                            +'<td class="xfqg_td10 price" >'+discount_price+'</td>'//价格
                            +'<td class="numberbarwq">'+addnum+'</td>'//数量
                            +'<td class="xfqg_td12 Company">'+unit_name+'</td>'//单位
                            +'<td class="xfqg_td13 Smallplan">'+subtotal+'</td>'//小计
                          /*  +'<td class="rfqg_td14 PleaseData"><input  maxlength="120" value="'+arrivaltime+'" readonly/></td>'//要求到货时间
                            +'<td class="rfqg_td15 PurchaseData" created_time="\'+data[i].created_time+\'" update_time="\'+data[i].update_time+\'"><input value="'+datashu+'" readonly/></td>'*///要求到采购时间
                            +'<td class="rfqg_td16 cycle"><input disabled value="'+product_cycle+'"/></td>'//交货期
                            +'<td class="rfqg_td18 offers"><span>'+explanation+'</span></td>'//报价说明
                            + '<td class="rfqg_td18">'+abnormal_type+'</td>'//异常询价
                            + '<td class="rfqg_td18">'+abnormal_text+'</td>'//异常询价备注
                            +'<td class="xfqg_td17 rfqg_td15 operation" info_state="'+data[i].info_state+'">'+'<a style="margin-right: 10px;" class="matchProduct" >匹配商品</a>'+'<a href="javascript:void(0);" class="delProduct">删除</a>'+'</td>'
                            +'</tr>'
                      };
                $('#productList').empty().append(html+htmler);
               /* timeSet($('.PleaseData>input'));
                timeSet($('.PurchaseData>input'));*/
            }
        });
//商品清单 表格 相关的操作
// 添加已有商品
$('#addProduct').click(function () {
    url = 'addproducts.html?receiver_province=' + receiver_province + '&platform=' + platform+'&customer_id='+customer_id+'&member_id='+member_id+'&warehouse_code='+warehouse_code+'&customer_codes='+customer_codes;
    title = '添加商品';
    goNextPage(title, url);
});

/*计数器功能*/

// 减数量
function number_decrease(el) {
    var money = $(el).next().next().val() //当前数值
    if ($(el).parent().parent().prev().children().length > 0) {
        var suanMoney = $(el).parent().parent().prev().find('input').val();
    } else {
        var suanMoney = $(el).parent().parent().prev().text();
    }
    if (money == '') {
        return false;
    } else if (money > 1) {
        $(el).next().next().val(Number(money) - 1)
        $(el).parent().parent().next().next().text((Number(money) - Number(1)) * Number(suanMoney).toFixed(2))
        return false
    } else {
        layer.msg('已是最小值', {icon: 5, time: 1000});
    }
}

// 加数量
function number_increase(el) {
    var money = $(el).next().val();
    if ($(el).parent().parent().prev().children().length > 0) {
        var suanMoney = $(el).parent().parent().prev().find('input').val();
    } else {
        var suanMoney = $(el).parent().parent().prev().text();
    }
    if (money == '') {
        return false;
    } else if (money < 99999) {
        $(el).next().val(Number(money) + 1)
        $(el).parent().parent().next().next().text(((Number(money) + Number(1)) * Number(suanMoney)).toFixed(2))
        return false
    }
    {
        layer.msg('已是最大值', {icon: 5, time: 1000});
    }
}

//校验价格
function checkPrice(el) {
    //限制只能输入两位小数
    el.value = el.value.replace(/[^\d.]/g,""); //清除"数字"和"."以外的字符
    el.value = el.value.replace(/^\./g,""); //验证第一个字符是数字
    el.value = el.value.replace(/\.{2,}/g,"."); //只保留第一个, 清除多余的
    el.value = el.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
    el.value = el.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'); //只能输入两个小数

    var money = $(el).val();
    var reg = /^([0-9]\d*(\.\d*[1-9])?)|(0\.\d*[1-9])$/;
    if (!reg.test(money)) {
        $(el).val('');
        $(el).parents('tr').find('td.Smallplan').text('0');
        return false;
    }
    var product_count = $(el).parents('tr').find('td.numberbarwq input').val();
    var suanMoney = (parseFloat(money) * parseInt(product_count)).toFixed(2);
    $(el).parents('tr').find('td.Smallplan').text(suanMoney);
}

/*校验数量*/
function checkCount(el, dang) {
    if ($(el).parents('td').prev().children().length > 0) {
        var money = $(el).parents('td').prev().find('input').val();
    } else {
        var money = $(el).parents('td').prev().text();
    }

    zheng = /^[1-9]\d*$/;
    if (el.value == '') {
        el.value = 1
    }
    if (!zheng.test(el.value)) {
        layer.msg('请输入正整数', {icon: 5, time: 1000});
        el.value = dang
    }
    if (money == '') {
        return false;
    }
    var suanMoney = (Number(el.value) * money).toFixed(2);
    // 改变小计价格
    $(el).parent().parent().next().next().text(suanMoney)
}

//成本价校验
$('#productList').on('blur', '.Costprice input', function () {

    var reg=/^\d+(\.\d{0,2})?$/;
    if (!reg.test($(this).val()) || $(this).val() == '0') {
        layer.msg('请输入大于0的数字,且最多能有两位小数！', {icon: 5, time: 1000});
        $(this).val('');
        return false;
    }
})
//交货期校验
$('#productList').on('blur', '.cycle input', function () {
    var reg = /^\+?[1-9][0-9]*$/;
    if (!reg.test($(this).val())) {
        layer.msg('交货期是必填,且是正整数！', {icon: 5, time: 2000});
        return false;
    }
});

// 跳转
function goNextPage(title, url) {
    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);
}

//添加已有商品回调
function dataListAdd(product_count, skucodes) {
    $.ajax({
        contentType: "application/json",
        type: "POST",
        url: root.xunjiadan.searchSkuInfoDetailByPage,
        cache: false,  //禁用缓存
        dataType: "json",
        data: JSON.stringify({
            "pageNum":1,
            "pageSize":10,
            "cityCode":receiver_province,
            "skuCode":skucodes,
            "warehouseId":warehouse_code,
            "memberId":member_id,
            "customerCode":customer_codes
        }),
        success: function (result) {
            if (result.errorCode == '0') {
                var data = result.data.data[0];
                var html = '';

                var order = $('#productList>tr').length + 1;
                //价格
                if (data.salePrice) {
                    var discountPrice = data.salePrice;
                } else {
                    var discountPrice = ""
                }
                //小计
                var subtotal = (parseFloat(discountPrice) * parseInt(product_count)).toFixed(2);
                //图片路径
                if (data.imgDtos) {
                    var img_url = data.imgDtos[0].imgUrl
                } else {
                    var img_url = '';
                }
                html += '<tr id="">'
                    + '<td class="rfqg_td1 order">' + order + '</td>'
                    + '<td class="xfqg_td2 commodityCode"  sku_id="' + data.skuId + '" spu_id="' + data.spuId + '">' + data.skuCode + '</td>'//商品编码
                    + '<td class="xfqg_td3 commodityName">' + data.skuName + '</td>'//商品名称
                    + '<td class="rfqg_td4 platformName">' + data.skuName + '</td>' //平台商品名称
                    + '<td class="xfqg_td5 fication">' + data.categoryName + '</td>'//分类
                    + '<td class="xfqg_td6 brand">' + data.brandName + '</td>'//品牌
                    + '<td class="xfqg_td7 describe">' + '<img style="width:24px;height:auto;" src ="' + img_url + '"/>' + data.skuName + '</td>'//商品描述
                    + '<td class="rfqg_td8 Please"></td>'//订货要求
                    + '<td class="rfqg_td10 Costprice"></td>'//成本价
                    + '<td class="xfqg_td10 price">' + discountPrice + '</td>'//价格
                    + '<td class="numberbarwq"><div class="numberbar"><span onclick="number_decrease(this)" class="number_decrease">-</span><span onclick="number_increase(this)" class="number_increase">+</span><input id="Smallplan"  maxlength="5" type="text"  oninput="checkCount(this,1)" class="num_text Numberwo" value="' + product_count + '"></div></td>'//数量
                    + '<td class="xfqg_td12 Company">' + data.unitName + '</td>'//单位
                    + '<td class="xfqg_td13 Smallplan">' + subtotal + '</td>'//小计
                    /*       + '<td class="rfqg_td14 PleaseData"><input value="" readonly/></td>'//要求到货时间
                           + '<td class="rfqg_td14 PurchaseData"><input value="" readonly/></td>'//要求到采购时间*/
                    + '<td class="rfqg_td16 cycle"><input disabled value="1"></td>'//交货期
                    +'<td class="rfqg_td18 offers"><span></span></td>'//报价说明
                    + '<td class="rfqg_td18"></td>'//异常询价
                    + '<td class="rfqg_td18"></td>'//异常询价备注
                    + '<td class="xfqg_td17 rfqg_td15 operation" info_state="10"><a style="margin-right: 10px;" class="matchProduct" >再次匹配商品</a>' + '<a href="javascript:void(0);" class="delProduct">删除</a>' + '</td>'
                    + '</tr>';
                $('#productList').append(html);
                /*timeSet($('.PleaseData>input'));
                timeSet($('.PurchaseData>input'));*/
            }
        },
        error: function (data) {
        }

    })
}


// 匹配商品回调
function datalsit(el, dali, order) {
    $.ajax({
        contentType: "application/json",
        type: "POST",
        url: root.xunjiadan.searchSkuInfoDetailByPage,
        cache: false,  //禁用缓存
        dataType: "json",
        data: JSON.stringify({
            "pageNum":1,
            "pageSize":10,
            "cityCode":receiver_province,
            "skuCode":dali[0],
            "warehouseId":warehouse_code,
            "memberId":member_id,
            "customerCode":customer_codes
        }),
        success: function (result) {
            // alert(Only)
            if (result.errorCode == 0) {
                var html = ''
                var data = result.data.data[0];
                $('#productList tr').each(function (index, dom) {
                    if ($(dom).find('.order').text() == order) {
                        // alert("渲染")
                        // 保留的数据   序号 商品id   商品名称  订货要求   要求到货时间   要求采购时间
                        var id = $(dom).attr('id');
                        var product_name = $(dom).find('td.commodityName').text();//商品名称
                        if ($(dom).find('td.Please').children().length > 0) {
                            var Please = $(dom).find('td.Please input').val();//订货要求
                        } else {
                            var Please = $(dom).find('td.Please').text();
                        }
                        var Costprice = 0;//成本价
                        var PleaseData = $(dom).find('td.PleaseData input').val();//要求到货时间
                        var PurchaseData = $(dom).find('td.PurchaseData input').val();//要求到采购时间
                        if (data.imgDtos) {
                            var img_url = data.imgDtos[0].imgUrl
                        } else {
                            var img_url = '';
                        }
                        //价格
                        if (data.salePrice) {
                            var discountPrice = data.salePrice;
                        } else {
                            var discountPrice =""
                        }
                        //小计
                        var Smallplan = (Number(discountPrice) * Number(el)).toFixed(2);
                        html += '<tr id="' + id + '">'
                            + '<td class="rfqg_td1 order">' + order + '</td>'
                            + '<td class="xfqg_td2 commodityCode"  sku_id="' + data.skuId + '" spu_id="' + data.spuId + '">' + data.skuCode + '</td>'//商品编码
                            + '<td class="xfqg_td3 commodityName">' + product_name + '</td>'//商品名称
                            + '<td class="rfqg_td4 platformName">' + data.skuName + '</td>' //平台商品名称
                            + '<td class="xfqg_td5 fication">' + data.categoryName + '</td>'//分类
                            + '<td class="xfqg_td6 brand">' + data.brandName + '</td>'//品牌
                            + '<td class="xfqg_td7 describe">' + '<img style="width:24px;height:auto;" src = "' + img_url + '"/>' + data.skuName + '</td>'//商品描述
                            + '<td class="rfqg_td8 Please"></td>'//订货要求
                            + '<td class="rfqg_td10 Costprice"></td>'//成本价
                            + '<td class="xfqg_td10 price">' + discountPrice + '</td>'//价格
                            + '<td class="numberbarwq"><div class="numberbar"><span onclick="number_decrease(this)" class="number_decrease">-</span><span onclick="number_increase(this)" class="number_increase">+</span><input id="Smallplan"  maxlength="5" type="text"  oninput="checkCount(this,1)" class="num_text Numberwo" value="' + el + '"></div></td>'//数量
                            + '<td class="xfqg_td12 Company">' + data.unitName + '</td>'//单位
                            + '<td class="xfqg_td13 Smallplan">' + Smallplan + '</td>'//小计
                            /*              + '<td class="rfqg_td14 PleaseData"><input value="' + PleaseData + '" readonly/></td>'//要求到货时间
                                          + '<td class="rfqg_td14 PurchaseData"><input value="' + PurchaseData + '" readonly/></td>'//要求到采购时间*/
                            + '<td class="rfqg_td16 cycle"><input disabled value="1"></td>'//交货期
                            +'<td class="rfqg_td18 offers"><span></span></td>'//报价说明
                            + '<td class="rfqg_td18"></td>'//异常询价
                            + '<td class="rfqg_td18"></td>'//异常询价备注
                            + '<td class="xfqg_td17 rfqg_td15 operation" info_state="10"><a style="margin-right: 10px;" class="matchProduct">再次匹配商品</a>' + '<a href="javascript:void(0);" class="delProduct">删除</a>' + '</td>'
                            + '</tr>';
                        $(dom).replaceWith(html);
                       /* timeSet($('.PleaseData>input'));
                        timeSet($('.PurchaseData>input'));*/
                    }
                });
            }
        }
    })
}

// 保存功能
var isSave = false;

function Preservation(release, type) {
    var bool = true;
    if (isSave) {
        return false;
    }
    if (type == 'export') {
        $("#temporarySelect").attr('href', "javascript:void(0);");
    }
    //正常保存
    if (release == 1) {
        var index;
        var info = [];
        var all_number = 0;
        var exist_price_number = 0;
        var bool = true;
        var flag = true;


        if (!bool) {
            return false;
        }

        for (var i = 0; i < $('#productList>tr').length; i++) {
            var item = $($('#productList>tr')[i]);

            if (item.find('td.commodityCode').attr("sku_id") && item.find('td.commodityCode').attr("sku_id") != '0' && item.find('td.operation').attr('info_state') == '10') {
                exist_price_number++;
                //判断交货期是否已填写，并且必须是正整数
                var product_cycle = item.find('td.cycle input').val();
                var reg = /^\+?[1-9][0-9]*$/;
                if (!reg.test(product_cycle)) {
                    bool = false;
                    layer.msg('交货期为必填，且是正整数', {icon: 5, time: 1000});
                    return false;
                }
            }
            if (item.find('td.operation').attr('info_state') != '20') {
                all_number++;
            }
            //id
            var id = item.attr('id');
            //平台商品名称
            if (item.find('td.platformName').children().length > 0) {
                var sku_name = item.find('td.platformName input').val();
            } else {
                var sku_name = item.find('td.platformName').text();
            }
            var spu_id = item.find('td.commodityCode').attr('spu_id');
            if (item.find('td.fication').children().length > 0) {
                var fication = item.find('td.fication input').val();
            } else {
                var fication = item.find('td.fication').text()
            }
            if (item.find('td.brand').children().length > 0) { //品牌
                var brand = item.find('td.brand input').val();
            } else {
                var brand = item.find('td.brand').text()
            }
            if (item.find('td.Please').children().length > 0) { //订货要求
                var order_fillrates = item.find('td.Please input').val();
            } else {
                var order_fillrates = item.find('td.Please').text()
            }
            if (item.find('td.price').children().length > 0) {//销售价
                var price = item.find('td.price input').val();
            } else {
                var price = item.find('td.price').text()
            }
            if (item.find('td.Company').children().length > 0) {
                var Company = item.find('td.Company input').val();
            } else {
                var Company = item.find('td.Company').text();//商品单位名称

            }
            if (item.find('td.Costprice').children().length > 0) {  //成本价
                var Costprice = item.find('td.Costprice input').val()
            } else {
                var Costprice = item.find('td.Costprice').text()
            }
            var pic = item.find('td.describe img').attr('src');
            var desc = item.find('td.describe').text();
            var product_depict = JSON.stringify({"pic": pic, "desc": desc});
            var obj = {
                id: id||'0',//自增ID
                belong_inquiry_id: inquiry_id,//询价单号
                sku_id: item.find('td.commodityCode').attr('sku_id'),//skuid
                sku_code: item.find('td.commodityCode').text(),//商品编码
                product_name: item.find('td.commodityName').text(),//商品名称
                sku_name: sku_name,//平台的商品名称
                product_classify: fication,//商品分类
                brand: brand,//品牌
                product_depict: product_depict,//商品描述
                order_fillrates: order_fillrates,//订货要求
                price: Costprice,//成本价
                discount_price: price,//销售单价
                product_count: item.find('td.numberbarwq div input').val(),//数量
                unit_name: Company,//商品单位名称
                subtotal: item.find('td.Smallplan').text(),//小计
                claim_arrival_time: item.find('td.PleaseData input').val(),//要求到货时间
                claim_purchase_time: item.find('td.PurchaseData input').val(),//要求到采购时间
                product_cycle: item.find('td.cycle input').val(),//交货期
                spu_id: spu_id,
                info_state: item.find('td.operation').attr('info_state'),
                explanation: item.find('td.offers').text()
            };
            info.push(obj);
        }
        ;
        var orderProductsParams = {
            "async": false,
            "crossDomain": true,
            "url": root.xunjiadan.orderCheckUpdate,
            "method": "POST",
            "beforeSend": function () {
                index = layer.load();
            },
            "headers": {
                "Content-Type": "application/json"
            },
            "data": JSON.stringify({
                "manage": {
                    "inquiry_id": inquiry_id,
                    "all_number": all_number,
                    "exist_price_number": exist_price_number,
                    "inquiry_name": "",
                    "customer_id": "",
                    "customer_name": "",
                    "member_id": "",
                    "linkman": "",
                    "linkman_phone": "",
                    "receiver_province": "",
                    "receiver_province_name": "",
                    "receiver_city": "",
                    "receiver_city_name": "",
                    "receiver_area": "",
                    "receiver_area_name": "",
                    "detail_address": "",
                    "inquiry_status": "",
                    "back_reason": "",
                    "other_explain": "",
                    "inquiry_time": "",
                    "matcher_id": '',
                    "matching_name": '',
                    "matching_time": "",
                    "fix_price_id": '',
                    "fix_price_name": '',
                    "fix_price_time": "",
                    "claim_arrival_time":  $('#timemin').val(),
                    "claim_purchase_time":$('#timemax').val()
                },
                "info": info,
                "enterChange": {
                    "inquiry_id": inquiry_id,
                    "back": '6',
                    "state": state,
                    "matcher_id": '',
                    "matching_name": '',
                    "fix_price_id": fix_price_id,
                    "fix_price_name": fix_price_name
                }
            })
        }
        $.ajax(orderProductsParams).done(function (response) {
            layer.close(index);
            if (type == 'export') {
                if (response.code == '0') {
                    $("#temporarySelect").attr('href', root.xunjiadan.inquirySecondExcel + "?inquiry_id=" + inquiry_id);
                    /*setTimeout(function () {
                        $("#temporarySelect").click();
                    },1000)*/

                } else if (response.code == '70') {
                    layer.msg('该询价单已撤销！', {icon: 5, time: 1000});
                    setTimeout(function () {
                        window.parent.doSubmit();
                        var index = parent.layer.getFrameIndex(window.name);  // 关闭当前页面，并不刷新父级页面
                        parent.layer.close(index);
                    }, 1000)
                }else if (response.code == '1') {
                    layer.msg(response.message, {icon: 5, time: 1000});
                }
                else {
                    $.Huimodalalert('请完善数据', 2000);
                }
            } else {
                if (response.code == '0') {
                    layer.msg('保存成功', {icon: 6, time: 1000});
                    setTimeout(function () {
                        location.reload();
                    }, 1000);
                } else if (response.code == '70') {
                    layer.msg('该询价单已撤销！', {icon: 5, time: 1000});
                    setTimeout(function () {
                        window.parent.doSubmit();
                        var index = parent.layer.getFrameIndex(window.name);  // 关闭当前页面，并不刷新父级页面
                        parent.layer.close(index);
                    }, 1000)
                } else if (response.code == '1') {
                    layer.msg(response.message, {icon: 5, time: 1000});
                }else {
                    $.Huimodalalert('请完善数据', 2000);
                }
            }

        });
        // 释放
    } else if (release == 10) {
        var info = [];
        var all_number = 0;
        var exist_price_number = 0;
        for (var i = 0; i < $('#productList>tr').length; i++) {
            var item = $($('#productList>tr')[i]);
            if (item.find('td.commodityCode').attr("sku_id") && item.find('td.commodityCode').attr("sku_id") != '0' && item.find('td.operation').attr('info_state') == '10') {
                exist_price_number++;
                //判断交货期是否已填写，并且必须是正整数
                var product_cycle = item.find('td.cycle input').val();
                var reg = /^\+?[1-9][0-9]*$/;
                if (!reg.test(product_cycle)) {
                    bool = false;
                    layer.msg('交货期为必填，且是正整数', {icon: 5, time: 1000});
                    return false;
                }
            }
            if (item.find('td.operation').attr('info_state') != '20') {
                all_number++;
            }
            var id = item.attr('id');
            //平台商品名称
            if (item.find('td.platformName').children().length > 0) {
                var sku_name = item.find('td.platformName input').val();
            } else {
                var sku_name = item.find('td.platformName').text();
            }
            var spu_id = item.find('td.commodityCode').attr('spu_id');
            var product_name//商品名称
            if (item.find('td.fication').children().length > 0) {
                var fication = item.find('td.fication input').val();
            } else {
                var fication = item.find('td.fication').text()
            }
            if (item.find('td.brand').children().length > 0) { //品牌
                var brand = item.find('td.brand input').val();
            } else {
                var brand = item.find('td.brand').text()
            }
            if (item.find('td.Please').children().length > 0) { //订货要求
                var order_fillrates = item.find('td.Please input').val();
            } else {
                var order_fillrates = item.find('td.Please').text()
            }
            if (item.find('td.price').children().length > 0) {//销售价
                var price = item.find('td.price input').val();
            } else {
                var price = item.find('td.price').text()
            }
            if (item.find('td.Company').children().length > 0) {
                var Company = item.find('td.Company input').val();
            } else {
                var Company = item.find('td.Company').text();//商品单位名称

            }
            if (item.find('td.Costprice').children().length > 0) {  //成本价
                var Costprice = item.find('td.Costprice input').val()
            } else {
                var Costprice = item.find('td.Costprice').text()
            }
            var pic = item.find('td.describe img').attr('src');
            var desc = item.find('td.describe').text();
            var product_depict = JSON.stringify({"pic": pic, "desc":  desc});
            var obj = {
                id: id||'0',//自增ID
                belong_inquiry_id: inquiry_id,//询价单号
                sku_id: item.find('td.commodityCode').attr('sku_id'),//skuid
                sku_code: item.find('td.commodityCode').text(),//商品编码
                product_name: item.find('td.commodityName').text(),//商品名称
                sku_name: sku_name,//平台的商品名称
                product_classify: fication,//商品分类
                brand: brand,//品牌
                product_depict: product_depict,//商品描述
                order_fillrates: order_fillrates,//订货要求
                price: Costprice,//成本价
                discount_price: price,//销售单价
                product_count: item.find('td.numberbarwq div input').val(),//数量
                unit_name: Company,//商品单位名称
                subtotal: item.find('td.Smallplan').text(),//小计
                claim_arrival_time: item.find('td.PleaseData input').val(),//要求到货时间
                claim_purchase_time: item.find('td.PurchaseData input').val(),//要求到采购时间
                product_cycle: item.find('td.cycle input').val(),//交货期
                spu_id: spu_id,
                info_state: item.find('td.operation').attr('info_state'),
                explanation: item.find('td.offers').text()
            };
            info.push(obj);

        }
        ;
        var orderProductsParams = {
            "async": true,
            "crossDomain": true,
            "url": root.xunjiadan.orderCheckUpdate,
            "method": "POST",
            "headers": {
                "Content-Type": "application/json"
            },
            "data": JSON.stringify({
                "manage": {
                    "inquiry_id": inquiry_id,
                    "all_number": all_number,
                    "exist_price_number": exist_price_number,
                    "inquiry_name": "",
                    "customer_id": "",
                    "customer_name": "",
                    "member_id": "",
                    "linkman": "",
                    "linkman_phone": "",
                    "receiver_province": "",
                    "receiver_province_name": "",
                    "receiver_city": "",
                    "receiver_city_name": "",
                    "receiver_area": "",
                    "receiver_area_name": "",
                    "detail_address": "",
                    "inquiry_status": "",
                    "back_reason": "",
                    "other_explain": "",
                    "inquiry_time": "",
                    "matcher_id": matcher_id,
                    "matching_name": matching_name,
                    "matching_time": "",
                    "fix_price_id": "",
                    "fix_price_name": "",
                    "fix_price_time": "",
                    "claim_arrival_time":  $('#timemin').val(),
                    "claim_purchase_time":$('#timemax').val()
                },
                "info": info,
                "enterChange": {
                    "inquiry_id": inquiry_id,
                    "back": 2,
                    "state": state,
                    "matcher_id": matcher_id,
                    "matching_name": matching_name,
                    "fix_price_id": fix_price_id,
                    "fix_price_name": fix_price_name
                }
            })
        }
        $.ajax(orderProductsParams).done(function (response) {
            if (response.code == '0') {
                layer.msg('释放成功', {icon: 6, time: 1000});
                setTimeout(function () {
                    window.parent.doSubmit();
                    var index = parent.layer.getFrameIndex(window.name);  // 关闭当前页面，并不刷新父级页面
                    parent.layer.close(index);
                }, 1000)
            } else if (response.code == '70') {
                layer.msg('该询价单已撤销！', {icon: 5, time: 1000});
                setTimeout(function () {
                    window.parent.doSubmit();
                    var index = parent.layer.getFrameIndex(window.name);  // 关闭当前页面，并不刷新父级页面
                    parent.layer.close(index);
                }, 1000)
            } else if (response.code == '1') {
                layer.msg(response.message, {icon: 5, time: 1000});
            }else {
                $.Huimodalalert('请完善数据', 2000);
            }

        });
        // 报价完成
    } else if (release == 2) {
        var back = "3";
        var info = [];
        var all_number = 0;
        var exist_price_number = 0;
        var bool = true;

        //效验商品编码是否重复&平台商品名称+商品描述是否存在相同条目
        verificationall=true
        commodityCode()
        if(verificationall==false){
            bool = false;
        }else {
            bool = true;
        }

        if (!bool) {
            return false;
        }



        for (var i = 0; i < $('#productList>tr').length; i++) {
            var item = $($('#productList>tr')[i]);
            if (item.find('td.operation').attr('info_state') != '20') {
                all_number++;
            }
            if (item.find('td.commodityCode').attr("sku_id") && item.find('td.commodityCode').attr("sku_id") != '0' && item.find('td.operation').attr('info_state') == '10' || item.find('td.operation').attr('info_state') == '10' && item.find('td.price input').val() != '' && item.find('td.price input').val() != '0') {
                exist_price_number++;
                //判断交货期是否已填写，并且必须是正整数
                var product_cycle = item.find('td.cycle input').val();
                var reg = /^\+?[1-9][0-9]*$/;
                if (!reg.test(product_cycle)) {
                    bool = false;
                    layer.msg('交货期为必填，且是正整数', {icon: 5, time: 1000});
                    return false;
                }

            }
            //平台商品名称
            if (item.find('td.platformName').children().length > 0) {
                var sku_name = item.find('td.platformName input').val();
            } else {
                var sku_name = item.find('td.platformName').text();
            }
            var spu_id = item.find('td.commodityCode').attr('spu_id');
            var product_name//商品名称
            if (item.find('td.fication').children().length > 0) {
                var fication = item.find('td.fication input').val();
            } else {
                var fication = item.find('td.fication').text()
            }
            if (item.find('td.brand').children().length > 0) { //品牌
                var brand = item.find('td.brand input').val();
            } else {
                var brand = item.find('td.brand').text()
            }
            if (item.find('td.Please').children().length > 0) { //订货要求
                var order_fillrates = item.find('td.Please input').val();
            } else {
                var order_fillrates = item.find('td.Please').text()
            }
            if (item.find('td.price').children().length > 0) {//销售价
                var price = item.find('td.price input').val();
            } else {
                var price = item.find('td.price').text()
            }
            if (item.find('td.Company').children().length > 0) {
                var Company = item.find('td.Company input').val();
            } else {
                var Company = item.find('td.Company').text();//商品单位名称

            }
            if (item.find('td.Costprice').children().length > 0) {  //成本价
                var Costprice = item.find('td.Costprice input').val()
            } else {
                var Costprice = item.find('td.Costprice').text()
            }
            var pic = item.find('td.describe img').attr('src');
            var desc = item.find('td.describe').text();
            var product_depict = JSON.stringify({"pic": pic, "desc": desc});
            var obj = {
                id: item.attr('id')||'0',//自增ID
                belong_inquiry_id: inquiry_id,//询价单号
                sku_id: item.find('td.commodityCode').attr('sku_id'),//skuid
                sku_code: item.find('td.commodityCode').text(),//商品编码
                product_name: item.find('td.commodityName').text(),//商品名称
                sku_name: sku_name,//平台的商品名称
                product_classify: fication,//商品分类
                brand: brand,//品牌
                product_depict: product_depict,//商品描述
                order_fillrates: order_fillrates,//订货要求
                price: Costprice,//成本价
                discount_price: price,//销售单价
                product_count: item.find('td.numberbarwq div input').val(),//数量
                unit_name: Company,//商品单位名称
                subtotal: item.find('td.Smallplan').text(),//小计
                claim_arrival_time: item.find('td.PleaseData input').val(),//要求到货时间
                claim_purchase_time: item.find('td.PurchaseData input').val(),//要求到采购时间
                product_cycle: item.find('td.cycle input').val(),//交货期
                spu_id: spu_id,
                info_state: item.find('td.operation').attr('info_state'),
                explanation: item.find('td.offers').text()
            };
            info.push(obj);

        }
        ;
        if (!bool) {
            return false;
        }
        if (parseInt(all_number) - parseInt(exist_price_number) > 0) {
            layer.confirm('您还有' + (parseInt(all_number) - parseInt(exist_price_number)) + '个商品未报价，您确定要完成报价吗？', {
                btn: ['确定', '返回'] //按钮
            }, function (index, layero) {
                //完成报价的ajax
                layer.close(index);
                quotationCompletionCallback(info, all_number, exist_price_number, state);
            }, function () {
            });
        }
        if (parseInt(all_number) - parseInt(exist_price_number) == 0) {
            layer.confirm('您确定要完成报价吗?', {
                btn: ['确定', '返回'] //按钮
            }, function (index, layero) {
                layer.close(index);
                //完成报价的ajax
                quotationCompletionCallback(info, all_number, exist_price_number, state);
            }, function () {
            });
        }
    }
}

/* function exportdata() {
       // Preservation()
       if(Preservation(1,'export')){

           return false
       }
   }*/
//添加备注
$('#addRemarks').click(function () {
    var result = $('#remarks').val();
    if (result == "") {
        layer.msg('备注不能为空', {icon: 5, time: 1000});
        return false
    }
    var create_time = $.nowDate();
    var addRemParams = {
        "async": true,
        "crossDomain": true,
        "url": root.xunjiadan.addRemarks,
        "method": "POST",
        "headers": {
            "Content-Type": "application/json"
        },
        "processData": false,
        "data": JSON.stringify({
            "belong_inquiry_id": inquiry_id,            //询价单编号
            "service_id": service_id,
            "service_name": service_name,
            "create_time": create_time,
            "result": result
        })
    }
    //添加备注成功
    $.ajax(addRemParams).done(function (response) {
        $('#remarks').val('');
        if (response.code == '0') {
            $('#remarkTable').show();
            $('#remarksList').append('<tr><td>' + response.service_name + '</td><td>' + response.result + '</td><td>' + response.create_time + '</td><td id="' + response.id + '"><a href="javascript:void(0);" class="deleteRemarks">删除</a></td></tr>');
            layer.msg('添加成功！', {icon: 6, time: 1000});
        } else {
            layer.msg(response.response, {icon: 5, time: 1000});
        }
    });
})
//删除备注
$('#remarkTable').on('click', '.deleteRemarks', function () {
    var Result_id = $(this).parent('td').attr('id');
    var ele = $(this);
    var settings6 = {
        "async": true,
        "crossDomain": true,
        "url": root.xunjiadan.deleteRemarks,
        "method": "POST",
        "headers": {
            "Content-Type": "application/x-www-form-urlencoded"
        },
        "data": {
            "Result_id": Result_id
        }
    }
    $.ajax(settings6).done(function (response) {
        if (response.code == '0') {
            layer.msg('删除成功', {icon: 6, time: 1000});
            ele.parents('tr').remove();
            if ($('#remarksList tr').length == 0) {
                $('#remarkTable').hide();
            }
        } else {
            alert(response.message);
        }
    });
});
$('#productList').on('click', '.matchProduct', function () {
    var tr = $(this).parents('tr');
    var order = tr.find('.rfqg_td1').text();
    var product_name = tr.find('td.commodityName').text();
    if (tr.find('.Company').children().length > 0) {
        var unit_name = tr.find('.Company input').val();
    } else {
        var unit_name = tr.find('.Company').text();
    }
    var product_count = tr.find('td.numberbarwq input').val();
    if(product_count==undefined){
        var product_count = tr.find('td.numberbarwq').html();

    }
    var product_depict = tr.find('td.describe').text();
    url = "matchproducts.html?inquiry_id=" + encodeURI(inquiry_id) + '&order=' + order + '&product_name=' + product_name + '&product_count=' + product_count + '&unit_name=' + unit_name + '&product_depict=' + product_depict+'&receiver_province='+receiver_province+'&platform='+platform+'&customer_id='+customer_id+'&member_id='+member_id+'&customer_codes='+customer_codes+'&warehouse_code='+warehouse_code;
    title = "匹配商品";
    //防止自由输入项内容含#，getQueryString无法识别
    window.sessionStorage.setItem('member_id', member_id)
    window.sessionStorage.setItem('customer_id', customer_id)
    window.sessionStorage.setItem('product_name', product_name)
    window.sessionStorage.setItem('unit_name', unit_name)
    window.sessionStorage.setItem('product_depict', product_depict)
    goNextPage(title, url)
});
// 商品删除功能
$('#productList').on('click', '.delProduct', function () {
    $(this).parent().attr({"info_state": "20"});
    $(this).parent().parent().hide();
});
// 退回
$('#returnModalBtn').click(function () {
    var back_reason = $('#back_reason').val();
    if (back_reason == '') {
        alert('退回原因为必填！');
        return false;
    }
    ajaxInquirySecondSave(inquiry_id, '', '', [], '3', state, matcher_id, matching_name, fix_price_id, fix_price_name, back_reason);
});

function ajaxInquirySecondSave(inquiry_id, all_number, exist_price_number, info, back, state, matcher_id, matching_name, fix_price_id, fix_price_name, back_reason) {
    if (back == '3') {
        var back_reason = back_reason
    } else {
        var back_reason = '';
    }
    var orderCheckUpdateparams = {
        "async": true,
        "crossDomain": true,
        "url": root.xunjiadan.orderCheckUpdate,
        "method": "POST",
        "headers": {
            "Content-Type": "application/json"
        },
        "data": JSON.stringify({
            "manage": {
                "inquiry_id": inquiry_id,
                "all_number": all_number,
                "exist_price_number": exist_price_number,
                "inquiry_name": "",
                "customer_id": "",
                "customer_name": "",
                "member_id": "",
                "linkman": "",
                "linkman_phone": "",
                "receiver_province": "",
                "receiver_province_name": "",
                "receiver_city": "",
                "receiver_city_name": "",
                "receiver_area": "",
                "receiver_area_name": "",
                "detail_address": "",
                "inquiry_status": "",
                "back_reason": back_reason,
                "other_explain": "",
                "inquiry_time": "",
                "matcher_id": matcher_id,
                "matching_name": matching_name,
                "matching_time": "",
                "fix_price_id": "",
                "fix_price_name": "",
                "fix_price_time": "",
                "claim_arrival_time":  $('#timemin').val(),
                "claim_purchase_time":$('#timemax').val()
            },
            "info": info,
            "enterChange": {
                "inquiry_id": inquiry_id,
                "back": back,
                "state": state,
                "matcher_id": matcher_id,
                "matching_name": matching_name,
                "fix_price_id": fix_price_id,
                "fix_price_name": fix_price_name
            }
        })
    };
    $.ajax(orderCheckUpdateparams).done(function (response) {
        if (response.code == '0') {
            if (back == '2') {
                $('#ReleasedSuccessfully').modal('show');
                // history.go(-1);
            } else if (back == '5') {
                $('#CompleteQuotationSuccess').modal('show');
            } else if (back == '3') {
                $('#ReturnReason').modal('hide');
            } else if (back == '4') {
                $('#TemporarySelectSuccessfully').modal('show');
            } else {

            }
        } else {
            alert(response.message);
        }
    });
}

//完成报价的ajax
function quotationCompletionCallback(info, all_number, exist_price_number, state) {
    var orderProductsParams = {
        "async": true,
        "crossDomain": true,
        "url": root.xunjiadan.orderCheckUpdate,
        "method": "POST",
        "headers": {
            "Content-Type": "application/json"
        },
        "data": JSON.stringify({
            "manage": {
                "inquiry_id": inquiry_id,
                "all_number": all_number,
                "exist_price_number": exist_price_number,
                "inquiry_name": "",
                "customer_id": "",
                "customer_name": "",
                "member_id": "",
                "linkman": "",
                "linkman_phone": "",
                "receiver_province": "",
                "receiver_province_name": "",
                "receiver_city": "",
                "receiver_city_name": "",
                "receiver_area": "",
                "receiver_area_name": "",
                "detail_address": "",
                "inquiry_status": "",
                "back_reason": "",
                "other_explain": "",
                "inquiry_time": "",
                "matcher_id": '',
                "matching_name": '',
                "matching_time": "",
                "fix_price_id": "",
                "fix_price_name": "",
                "fix_price_time": "",
                "claim_arrival_time":  $('#timemin').val(),
                "claim_purchase_time":$('#timemax').val()
            },
            "info": info,
            "enterChange": {
                "inquiry_id": inquiry_id,
                "back": 5,
                "state": state,
                "matcher_id": '',
                "matching_name": '',
                "fix_price_id": fix_price_id,
                "fix_price_name": fix_price_name
            }
        })
    };
    $.ajax(orderProductsParams).done(function (response) {
        if (response.code == '0') {
            layer.msg('询价单已报价成功,发送短信成功', {icon: 6, time: 1000});
            setTimeout(function () {
                window.parent.doSubmit();
                var index = parent.layer.getFrameIndex(window.name);  // 关闭当前页面，并不刷新父级页面
                parent.layer.close(index);
            }, 1000);
        } else if (response.code == '70') {
            layer.msg('该询价单已撤销！', {icon: 5, time: 1000});
            setTimeout(function () {
                window.parent.doSubmit();
                var index = parent.layer.getFrameIndex(window.name);  // 关闭当前页面，并不刷新父级页面
                parent.layer.close(index);
            }, 1000)
        }else if (response.code == '1') {
            layer.msg(response.message, {icon: 5, time: 1000});
        } else {
            $.Huimodalalert('请完善数据', 2000);
        }
    });
}

function timeSet(ele) {
    ele.each(function (index, dom) {
        $.jeDate(dom, {
            format: "YYYY-MM-DD"
        });
    });

}
var len
var Preser
var common=8//要限制输入的字数
function checkMaxIut(me) {
    var text=$(me).val()
    strlen(text)
    if(len>common){
        $(me).val(Preser)
    }else {
        Preser=$(me).val()
    }
}
function strlen(str){
    len = 0;
    for (var i=0; i<str.length; i++) {
        var c = str.charCodeAt(i);
        //单字节加1
        if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {
            len++;
        } else {
            len+=2;
        }
    }
    return len;
}
//操作日志
function operationlog() {
    sessionStorage.setItem("inquiry_id",inquiry_id)
    var title="操作日志"
    var url="operationLog.html"
    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);
}
function getPorductList() {
    var info = [];
    var all_number = 0;
    var exist_price_number = 0;
    for (var i = 0; i < $('#productList>tr').length; i++) {
        var item = $($('#productList>tr')[i]);
        if (item.find('td.rfqg_td2').attr('sku_id') == '0' || item.find('td.rfqg_td2').attr('sku_id') == '') { // 未匹配
            if (item.find('.rfqg_td7').children().length > 1) {
                var desc = item.find('.rfqg_td7 input').val();
            } else {
                var desc = item.find('.rfqg_td7').text();
            }
            var pic = item.find('.rfqg_td7 img').attr('src');
            var product_depict = JSON.stringify({ "desc": desc, "pic": pic });

            if (item.find('.rfqg_td3').children().length > 0) {
                var product_name = item.find('.rfqg_td3 input').val();
            } else {
                var product_name = item.find('.rfqg_td3').text();
            }
            if (item.find('td.price').children().length > 0) { //销售价
                var price = item.find('td.price input').val();
            } else {
                var price = item.find('td.price').text()
            }
            if (item.find('td.Costprice').children().length > 0) { //成本价
                var Costprice = item.find('td.Costprice input').val()
            } else {
                var Costprice = item.find('td.Costprice').text()
            }
            var obj = {
                id: item.attr('id') || '0',
                belong_inquiry_id: inquiry_id,
                sku_id: item.find('td.rfqg_td2').attr('sku_id'),
                spu_id: item.find('td.rfqg_td2').attr('spu_id'),
                sku_code: item.find('td.rfqg_td2').text(),
                product_name: product_name,
                sku_name: item.find('.rfqg_td4 input').val(),
                product_classify: item.find('.rfqg_td5 input').val(),
                brand: item.find('.rfqg_td6 input').val(),
                product_depict: product_depict,
                order_fillrates: item.find('.rfqg_td8 input').val(),
                price: Costprice,
                discount_price: price,
                product_count: item.find('td.numberbarwq div input').val(),
                unit_name: item.find('.rfqg_td11 input').val(),
                subtotal: item.find('td.rfqg_td12').text(),
                product_cycle: '',
                claim_arrival_time: item.find('.rfqg_td13 input').val(),
                claim_purchase_time: item.find('.rfqg_td14 input').val(),
                info_state: item.find('.rfqg_td15').attr('info_state')
            };
        } else { // 已匹配
            if (item.find('td.rfqg_td15').attr('info_state') == '10') {
                exist_price_number++;
            }
            if (item.find('td.price').children().length > 0) { //销售价
                var price = item.find('td.price input').val();
            } else {
                var price = item.find('td.price').text()
            }
            if (item.find('td.Costprice').children().length > 0) { //成本价
                var Costprice = item.find('td.Costprice input').val()
            } else {
                var Costprice = item.find('td.Costprice').text()
            }
            var desc = item.find('.rfqg_td7').text();
            var pic = item.find('.rfqg_td7 img').attr('src');
            var product_depict = JSON.stringify({ "desc": desc, "pic": pic });
            var obj = {
                id: item.attr('id') || '0',
                belong_inquiry_id: inquiry_id,
                sku_id: item.find('td.rfqg_td2').attr('sku_id'),
                spu_id: item.find('td.rfqg_td2').attr('spu_id'),
                sku_code: item.find('td.rfqg_td2').text(),
                product_name: item.find('td.rfqg_td3').text(),
                sku_name: item.find('td.rfqg_td4').text(),
                product_classify: item.find('td.rfqg_td5').text(),
                brand: item.find('td.rfqg_td6').text(),
                product_depict: product_depict,
                order_fillrates: item.find('.rfqg_td8 input').val(),
                price: Costprice,
                discount_price: price,
                product_count: item.find('td.numberbarwq div input').val(),
                unit_name: item.find('td.rfqg_td11').text(),
                subtotal: item.find('td.rfqg_td12').text(),
                product_cycle: "1",
                /*item.find('td.rfqg_td13').attr('product_cycle')*/
                claim_arrival_time: item.find('td.rfqg_td13').text(),
                claim_purchase_time: item.find('td.rfqg_td14 input').val(),
                info_state: item.find('.rfqg_td15').attr('info_state')
            };
        }
        info.push(obj);
        if (item.find('td.rfqg_td15').attr('info_state') != '20') {
            all_number++;
        }
    };
    return {
        info: info,
        all_number: all_number,
        exist_price_number: exist_price_number
    }
}

function getManage(inquiry_id, all_number, exist_price_number) {
    var manage = {
        "inquiry_id": inquiry_id,
        "all_number": all_number,
        "exist_price_number": exist_price_number,
        "inquiry_name": "",
        "customer_id": "",
        "customer_name": "",
        "member_id": "",
        "linkman": "",
        "linkman_phone": "",
        "receiver_province": "",
        "receiver_province_name": "",
        "receiver_city": "",
        "receiver_city_name": "",
        "receiver_area": "",
        "receiver_area_name": "",
        "detail_address": "",
        "inquiry_status": "",
        "back_reason": "",
        "other_explain": "",
        "inquiry_time": "",
        "matcher_id": "",
        "matching_name": "",
        "matching_time": "",
        "fix_price_id": "",
        "fix_price_name": "",
        "fix_price_time": "",
        "claim_arrival_time":  $('#timemin').val(),
        "claim_purchase_time":$('#timemax').val()

    }
    return manage;
}

// 退回
$('#return').click(function () {
    //$('#ReturnReason').modal('show');
    var html = '<label style="margin-left:20px;vertical-align: top;line-height: 56px;"><span class="require">*</span>询价单退回原因：</label><textarea rows="10" id="back_reason2" style="width:300px;height:155px;margin-top: 20px;"></textarea>'
    layer.open({
        type: 1,
        titlle: '退回',
        area: ['500px', '300px'],
        content: html, //这里content是一个普通的String
        btn: ['确定', '取消'],
        btn1: function (index, layero) {
            back = "3";
            var back_reason = $('#back_reason2').val();
            if (back_reason == '') {
                layer.msg('退回原因为必填！', {icon: 5, time: 1000});
                return false;
            }
            layer.close(index);
            var productData = getPorductList();
            var all_number = productData.all_number;
            var info = productData.info;
            var exist_price_number = productData.exist_price_number;
            console.log(inquiry_id)
            console.log(all_number)
            console.log(exist_price_number)
            var manage = getManage(inquiry_id, all_number, exist_price_number);
            manage.back_reason = back_reason;
            var params = {
                "async": true,
                "crossDomain": true,
                "url": root.xunjiadan.orderCheckUpdate,
                "method": "POST",
                "headers": {
                    "Content-Type": "application/json"
                },
                "data": JSON.stringify({
                    /* "manage":manage,*/
                    "info":info,
                    "manage": {
                        "back_reason": back_reason,
                        "inquiry_id": inquiry_id,
                    },
                    /* "info": [],*/
                    "enterChange": {
                        "inquiry_id": inquiry_id,
                        "back": back,
                        "state": state,
                        "matcher_id": matcher_id,
                        "matching_name": matching_name,
                        "fix_price_id": '',
                        "fix_price_name": ''
                    }
                })
            }

            $.ajax(params).done(function (response) {
                if (response.code == '0') {
                    $('#ReturnReason').modal('hide');
                    $('#Undo').modal('show');
                    layer.msg('该询价单已退回！', {icon: 5, time: 1000});
                } else if (response.code == '60') {
                    layer.msg('该询价单已退回！', {icon: 5, time: 1000});
                } else if (response.code == '70') {
                    layer.msg('该询价单已撤销！', {icon: 5, time: 1000});
                } else {
                    layer.msg(response.message, {icon: 5, time: 1000});
                    return false;
                }
                setTimeout(function () {
                    window.parent.doSubmit();
                    var index = parent.layer.getFrameIndex(window.name);  // 关闭当前页面，并不刷新父级页面
                    parent.layer.close(index);
                }, 1000);
            });
        }
    });
})

function commodityCode() {
    //效验商品编码是否重复&平台商品名称+商品描述是否存在相同条目
    var productList = $('#productList tr');
    var maop=[]
    var plm={}
    var codeids=[]
    for(var j=0;j<productList.length;j++) {
        if ($(productList[j]).find('.xfqg_td7 input').val() != undefined && $(productList[j]).find('.rfqg_td4 input').val() != undefined){
            plm = {
                "name": $(productList[j]).find('.xfqg_td7 input').val() +","+ $(productList[j]).find('.rfqg_td4 input').val()+","+$(productList[j]).find('.rfqg_td1').text(),

            }
        }else {

            if($(productList[j]).find('.rfqg_td4 ').text()==""){
                plm = {
                    "name": $(productList[j]).find('.xfqg_td7 ').text() +","+ $(productList[j]).find('.rfqg_td4 input').val()+","+$(productList[j]).find('.rfqg_td1').text(),
                }
            }else {
                plm = {
                    "name": $(productList[j]).find('.xfqg_td7 ').text() +","+ $(productList[j]).find('.rfqg_td4 ').text()+","+$(productList[j]).find('.rfqg_td1').text(),
                }
            }

        }
        if($(productList[j]).find('.xfqg_td17').attr("info_state")==10){
            maop.push(plm)
            codeids.push($(productList[j]).find('.xfqg_td2').text()+","+$(productList[j]).find('.rfqg_td1').text())
        }


    }

    var repeats=""
    var repeatcodes=""
    //判断code码
    $.each(codeids,function(k,fircode){
        $.each(codeids,function(h,sedcode) {
            if (k==h){
                return true;
            }
            if(fircode.split(',')[0]!=""){
                if (fircode.split(',')[0]==sedcode.split(',')[0]) {
                    var repeatcode='第<span>'+fircode.split(',')[1]+'</span>行:<span>'+fircode.split(',')[0]+'</span>'
                    repeatcodes+=repeatcode+","
                    var curInd2 = layer.confirm('商品编码重复！（'+repeatcodes+')', {title:'提示',btn: ['确定']}, function(index){
                        layer.close(curInd2);
                    },function(){
                        layer.close(curInd2);

                    });
                    verificationall = false;
                    return false;
                }
                addintercepts=0

            }else {
                addintercepts=1

            }

        })
    })
    if(addintercepts==1){
        repeats=''
        //判断平台商品名称+商品描述
        $.each(maop,function(i,first){
            $.each(maop,function(s,sed){
                if (i==s){
                    return true;
                }
                var fiestname=first.name.split(',')[0]+first.name.split(',')[1]
                var sedname=sed.name.split(',')[0]+sed.name.split(',')[1]
                if(fiestname!=""||sedname!=""){
                    if (fiestname==sedname){
                        var repeat='第<span>'+first.name.split(',')[2]+'</span>行:<span>'+first.name.split(',')[1]+'</span>+<span>'+first.name.split(',')[0]+'</span>'
                        if(repeat!=""){
                            repeats+=repeat+","
                            var curInd = layer.confirm('平台商品名称+商品描述存在相同条目！（'+repeats+')', {title:'提示',btn: ['确定']}, function(index){
                                layer.close(curInd);
                            },function(){
                                layer.close(curInd);

                            });
                            verificationall = false;
                            return false;
                        }

                    }

                }

            })
        })
    }
}